[자바] 데이터 형변환 :: 자바예제모음[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

자바예제모음
[1]
등록일:2008-05-07 09:39:56 (0%)
작성자:
제목:[자바] 데이터 형변환
1.  Wrapper  클래스
Wrapper  클래스는  기본  데이터를  클래스로  만들  수  있게하는  클래스들  입니다.  기본데이터를  다른  데이터형으로  바꿀때  많이  사용합니다.


-  byteValue(),  shortValue(),  intValue(),  longValue(),  floatValue(),  doubleValue()
기본  데이터형을  Wrapper한  클래스에  xxxValue()  메소드를  이용해서  해당  데이터  형의  값을  얻을  수  있다.

또한  기본  데이터형은  작은  범위로는  캐스팅을  하고,  큰  범위로는  자동으로  데이터형을  변환  할  수  있습니다.
=>참조



-  integer  to  String

int  i  =  14;
String  str  =  Integer.toString(i);
or
String  str  =  ""  +  i 

-  double  to  String
String  str  =  Double.toString(i); 

-  long  to  String
String  str  =  Long.toString(l); 

-  float  to  String
String  str  =  Float.toString(f); 

-  String  to  integer
str  =  "14";
int  i  =  Integer.valueOf(str).intValue();
or
int  i  =  Integer.parseInt(str); 

-  String  to  double
double  d  =  Double.valueOf(str).doubleValue();
 
-  String  to  long
long  l  =  Long.valueOf(str).longValue();
or
long  l  =  Long.parseLong(str); 

-  String  to  float
float  f  =  Float.valueOf(str).floatValue(); 

-  decimal  to  binary  (2진수)
int  i  =  14;
String  str  =  Integer.toBinaryString(i);

-  decimal  to  hexadecimal  (16진수)
int  i  =  14;
String  hexstr  =  Integer.toString(i,  16);
or
String  hexstr  =  Integer.toHexString(i);

-  hexadecimal  (16진수  String)  to  integer
int  i  =  Integer.valueOf("B8DA3",  16).intValue();
or
int  i  =  Integer.parseInt("B8DA3",  16); 

-  ASCII  code  to  String
int  i  =  14;
String  aChar  =  new  Character((char)i).toString();

-  char  to  ASCII  code  (int)
char  c  =  'a';
int  i  =  (int)  c;  //  value  97  decimal

-  String  to  ASCII  code
String  test  =  "abcd";
for  (  int  i  =  0;  i  <  test.length();  ++i  )  {
char  c  =  test.charAt(  i  );
int  i  =  (int)  c;
System.out.println(i);
}
[본문링크] [자바] 데이터 형변환
[1]
코멘트(이글의 트랙백 주소:/cafe/tb_receive.php?no=7519
작성자
비밀번호

 

SSISOCommunity

[이전]

Copyright byCopyright ⓒ2005, SSISO Community All Rights Reserved.